<template>
    <div class="box">
        <h1>sum:{{ sum }} </h1>
        <button @click="add">加</button>
    </div>
</template>

<script setup lang="ts"> 
import { storeToRefs } from 'pinia'
// 导入pinia实例
import { useCountStore } from '@/store/count' 
// 获取pinia实例
const countStore = useCountStore()
const { sum } = storeToRefs(countStore)
// 获取pinia中的数据
countStore.$subscribe((_,state)=>{
    localStorage.setItem('sum',JSON.stringify(state.sum))
})
const add = () => {
    countStore.add()
}

</script>
<style scoped>

</style>